Excel 2010 Scripting  - Close a read-only workbook without prompting to save

I have a workbook that provides drop down list data to group of worksheets.  It needs to be open, but I did not want it visible to the user.  So, I open it as:

Sub Auto_Open()
    Application.ScreenUpdating = False
    Set w = Workbooks
    w.Open Filename:="P:\Troy Personnel\2016\Summary\Personnel Budget Data.xlsm", UpdateLinks:=False, ReadOnly:=True 'this is the data file were going to be opening
    ActiveWindow.Visible = False
    ThisWorkbook.Activate
    Application.ScreenUpdating = True
End Sub

This works perfectly.  However, when the user closes Excel, it asks them to Save the file.  I do not want them to do that, which is why I opened in read-only mode.  They still can't save the file, but it is a prompt that I wanted to suppress.  I tried this:

Sub CloseandSave()
    w.Close SaveChanges:=False
End Sub

and this:

Sub Workbook_BeforeClose(Cancel as Boolean)
    w.Close SaveChanges:=False
End Sub

Neither work, and I tried to place messages into the close and it looks like it is not even running.  Please help this is a major pain!

Regards,

David

August 11th, 2015 9:02am

That did not work.

<Sigh>

This is a small thing, but it will really be a hassle with the end-users.

Free Windows Admin Tool Kit Click here and download it now
August 11th, 2015 9:11am

Does it help if you change

    w.Open Filename:="P:\Troy Personnel\2016\Summary\Personnel Budget Data.xlsm", _
        UpdateLinks:=False, ReadOnly:=True

to

    w.Open(Filename:="P:\Troy Personnel\2016\Summary\Personnel Budget Data.xlsm", _
        UpdateLinks:=False, ReadOnly:=True).Saved = True

August 11th, 2015 9:40am

And this?

Sub Auto_Open()
    Dim wb As Workbook
    Application.ScreenUpdating = False
    Set wb = Workbooks.Open(Filename:="P:\Troy Personnel\2016\Summary\Personnel Budget Data.xlsm", _
        UpdateLinks:=False, ReadOnly:=True)
    ActiveWindow.Visible = False
    wb.Saved = True
    ThisWorkbook.Activate
    Application.ScreenUpdating = True
End Sub

Free Windows Admin Tool Kit Click here and download it now
August 11th, 2015 10:27am

Syntax error.

I will work on fixing

August 11th, 2015 12:27pm

Which line causes the syntax error?
Free Windows Admin Tool Kit Click here and download it now
August 11th, 2015 12:55pm

Have you tried:

    Application.DisplayAlerts = False

just prior to the w.close?

cw

August 27th, 2015 12:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics